<!--包含头部文件-->
{include file="public/header" /}
<style>
    #inputBox{
        width: 100%;
        height: 40px;
        border: 1px solid cornflowerblue;
        color: cornflowerblue;
        border-radius: 20px;
        position: relative;
        text-align: center;
        line-height: 40px;
        overflow: hidden;
        font-size: 16px;
    }
    #inputBox input{
        width: 114%;
        height: 40px;
        opacity: 0;
        cursor: pointer;
        position: absolute;
        top: 0;
        left: -14%;
    }
    #imgBox{
        text-align: left;
    }
    .imgContainer{
        display: inline-block;
        width: 32%;
        height: 150px;
        margin-left: 1%;
        border: 1px solid #666666;
        position: relative;
        margin-top: 30px;
        box-sizing: border-box;
    }
    .imgContainer img{
        width: 100%;
        height: 150px;
        cursor: pointer;
    }
    .imgContainer p{
        position: absolute;
        bottom: -1px;
        left: 0;
        width: 100%;
        height: 30px;
        background: black;
        text-align: center;
        line-height: 30px;
        color: white;
        font-size: 16px;
        font-weight: bold;
        cursor: pointer;
        display: none;
    }
    .imgContainer:hover p{
        display: block;
    }
    .lubo_pic{float: left;margin: 0 auto;cursor:pointer;text-align: center;background-image: url("__STATIC__/images/default.jpg")}
</style>
<body>
<article class="page-container">
    <form class="form form-horizontal" action="" method="post" id="form-subject_items-add">
        <input type="hidden" class="input-text" value="{$data.itemid|default=0}" placeholder="" id="itemid" name="itemid"/>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>商品链接：</label>
            <div class="formControls col-xs-6 col-sm-6">
                {if condition="$data['shoptype'] eq 'B'"} <a href="https://detail.tmall.com/item.htm?id={$data['itemid']}" target="_blank" style="color: red">点击查看商品详情</a>
                {else/} <a href="https://item.taobao.com/item.htm?id={$data['itemid']}" target="_blank" style="color: red">点击查看商品详情</a>
                {/if}

            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>商品名称：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <input type="text" class="input-text" value="{$data.itemtitle|default=''}" placeholder="请输入商品标题" id="itemtitle" name="itemtitle"/>
            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>商品图片：</label>
            <div class="formControls col-xs-5 col-sm-5">
                <div class="lubo_pic" onclick="img_div(this)">
                    <img src="{$data.itempic|default='__STATIC__/images/default.jpg'}" width="150px" height="150px" id="img_show">
                </div>
                <input id="upload_img" name="activity_img" accept="image/*" onchange="uploadImgFile(this)" type="file" style="display: none"/>
                <input name="itempic" value="{$data.itempic|default=''}" type="hidden" />
            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>商品类型：</label>
            <div class="formControls col-xs-8 col-sm-8">
                <span class="select-box" style="width: auto">
                    <select name="cat_id" id="cat_id" class="select" style="width: auto">
                    <option value="0">请选择商品类别</option>
                        {volist name='catetype' id='vo'}
                    <option value="{$vo.id}" {if condition="$data['fqcat'] eq $vo.id"}selected {/if}>{$vo.name}</option>
                        {/volist}
                </select>
                </span>
            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3">活动类型：</label>
            <div class="formControls col-xs-8 col-sm-9 skin-minimal">
                <div class="radio-box">
                    <input name="activity_type[]" type="checkbox" id="activity-1" value="1" >
                    <label for="activity-1">甄选商品</label>
                </div>
                <div class="radio-box">
                    <input name="activity_type[]" type="checkbox" id="activity-2" value="2" >
                    <label for="activity-2">特价商品</label>
                </div>
                <div class="radio-box">
                    <input name="activity_type[]" type="checkbox" id="activity-3" value="3">
                    <label for="activity-3">量贩组合</label>
                </div>
            </div>
        </div>


        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>店铺：</label>
            <div class="formControls col-xs-8 col-sm-8">
                <span class="select-box" style="width: auto">
                    <select name="shop_id" id="shop_id" class="select" style="width: auto">
                    <option value="0">请选择店铺</option>
                        {volist name='shops' id='vo'}
                    <option value="{$vo.id}">{$vo.shop_name}</option>
                        {/volist}
                </select>
                </span>
            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>销量：</label>
            <div class="formControls col-xs-2 col-sm-2">
                <input type="text" class="input-text" value="{$data['itemsale']|default=0}" placeholder="请输入月销量" id="itemsale" name="itemsale"/>
            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>商品在售价：</label>
            <div class="formControls col-xs-2 col-sm-2">
                <input type="text" class="input-text" value="{$data['itemprice']|default=0}" placeholder="请输入淘宝/天猫在售价格" id="itemprice" name="itemprice"/>
            </div>
        </div>


        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>库存：</label>
            <div class="formControls col-xs-2 col-sm-2">
                <input type="text" class="input-text" value="50" placeholder="请输入商品库存" id="store_count" name="store_count"/>
            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>排序：</label>
            <div class="formControls col-xs-2 col-sm-2">
                <input type="text" class="input-text" value="50" placeholder="请输入商品排序" id="sort" name="sort"/>
            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>淘宝/天猫：</label>
            <div class="formControls col-xs-8 col-sm-9 skin-minimal">
                <div class="radio-box">
                    <input name="shoptype" value="B" type="radio" id="status-1" {if condition="$data['shoptype'] eq 'B'"}checked {/if}>
                    <label for="status-1">天猫</label>
                </div>
                <div class="radio-box">
                    <input name="shoptype" type="radio" value="C" id="status-2" {if condition="$data['shoptype'] eq 'C'"}checked {/if}>
                    <label for="status-2">淘宝</label>
                </div>
            </div>
        </div>


        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>推荐：</label>
            <div class="formControls col-xs-8 col-sm-9 skin-minimal">
                <div class="radio-box">
                    <input name="tuijian" value="0" type="radio" id="tuijian-0" checked>
                    <label for="tuijian-0">否</label>
                </div>
                <div class="radio-box">
                    <input name="tuijian" type="radio" value="1" id="tuijian-1">
                    <label for="tuijian-1">是</label>
                </div>
            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>是否热卖：</label>
            <div class="formControls col-xs-8 col-sm-9 skin-minimal">
                <div class="radio-box">
                    <input name="is_hot" value="0" type="radio" id="is_hot-0" checked>
                    <label for="is_hot-0">否</label>
                </div>
                <div class="radio-box">
                    <input name="is_hot" type="radio" value="1" id="is_hot-1">
                    <label for="is_hot-1">是</label>
                </div>
            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>是否上架：</label>
            <div class="formControls col-xs-8 col-sm-9 skin-minimal">
                <div class="radio-box">
                    <input name="is_on_sale" value="0" type="radio" id="is_on_sale-0">
                    <label for="is_on_sale-0">否</label>
                </div>
                <div class="radio-box">
                    <input name="is_on_sale" type="radio" value="1" id="is_on_sale-1" checked>
                    <label for="is_on_sale-1">是</label>
                </div>
            </div>
        </div>

        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
            </div>
        </div>
    </form>
</article>

<!--包含footer文件-->
{include file="public/footer" /}

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="__STATIC__/lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="__STATIC__/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="__STATIC__/lib/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="__STATIC__/lib/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript" src="__STATIC__/js/ajaxfileupload.js"></script>

<script type="text/javascript">


    //点击图片上传
    function img_div(e) {
        $("#upload_img").click()
    }
    //    上传图片
    function uploadImgFile(even) {
        var id = even.id;
        $.ajaxFileUpload
        (
            {
                url: '{:url("Upload/img_upload")}',//需要链接到服务器地址
                secureuri: false,
                fileElementId: id,
                dataType: 'json',
                success: function (data)  //服务器成功响应处理函数
                {
                    var path = data.data.path;
                    var host_path = data.data.host_path;
                    $("#"+id).next().val(path);
                    $("#"+id).prev().children(':first').attr('src',host_path);
                },
                error: function (data, status, e)//服务器响应失败处理函数
                {
                    alert(e);
                }
            }
        )
        return false;

    }

    $(function () {

        $('#one_button').click(function () {
            var item_url = $('#item_url').val();
            if (item_url == ''){
                alert('商品链接不能为空')
                return false;
            }
            $.ajax({
                type: 'POST',
                url: "{:url('operate/ajax_getiteminfo')}",
                data: {item_url:item_url},
                dataType: 'json',
                success: function (data) {
                    if (data.code == 200){
                        $("#img_show").attr('src',data.data.itempic);
                        $("input[name='itempic']").val(data.data.itempic);
                        $("input[name='itemid']").val(data.data.itemid);
                        $("#itemtitle").val(data.data.title);
                        if (data.data.shoptype == 'B'){
                            $("#select_cate").val('B');
                        }else if (data.data.shoptype == 'C'){
                            $("#select_cate").val('C');
                        }
                        $("input[name='itemsale']").val(data.data.sell_counter);
                        $("input[name='itemprice']").val(data.data.price);
                        $(".textarea").val(data.data.desc);
                    }else {
                        layer.alert('添加失败'+data.msg+'',{
                            skin: 'layui-layer-molv' //样式类名 自定义样式
                            ,closeBtn: 0  // 是否显示关闭按钮
                            ,anim: 1 //动画类型
                            ,btn: '确认'//按钮
                            ,icon: 6  // icon
                        })
                    }
                },
                error:function () {

                }
            })
        })




        $('.skin-minimal input').iCheck({
            checkboxClass: 'icheckbox-blue',
            radioClass: 'iradio-blue',
            increaseArea: '20%'
        });

        $("#form-subject_items-add").validate({
            rules:{
                itemtitle:{
                    required:true,
                },
                itempic:{
                    required:true,
                },
                shoptype:{
                    required:true,
                },
                itemsale:{
                    required:true,
                },
                itemprice:{
                    required:true,
                }
            },
            onkeyup:false,
            focusCleanup:true,
            success:"valid",
            submitHandler:function(form){
                var arr = new FormData(document.getElementById("form-subject_items-add"));
                $.ajax({
                    url:"{:url('goods/add_goods')}",
                    type:"post",
                    data:arr,
                    async: true,
                    processData: false,
                    contentType: false,
                    dataType:"json",
                    success:function (data) {
                        if (data.code == 200){
                            layer.alert('添加成功',{
                                skin: 'layui-layer-molv' //样式类名 自定义样式
                                ,closeBtn: 0  // 是否显示关闭按钮
                                ,anim: 1 //动画类型
                                ,btn: '确认'//按钮
                                ,icon: 6  // icon
                                ,yes:function(){
                                    layer.closeAll();
                                    parent.location.reload();
                                }
                            })
                        }else {
                            layer.alert('添加失败'+data.msg+'',{
                                skin: 'layui-layer-molv' //样式类名 自定义样式
                                ,closeBtn: 0  // 是否显示关闭按钮
                                ,anim: 1 //动画类型
                                ,btn: '确认'//按钮
                                ,icon: 6  // icon
                            })
                        }

                    },
                    error:function () {
                        layer.alert('添加失败',{
                            skin: 'layui-layer-molv' //样式类名 自定义样式
                            ,closeBtn: 0  // 是否显示关闭按钮
                            ,anim: 1 //动画类型
                            ,btn: '确认'//按钮
                            ,icon: 6  // icon
                        })
                    }
                })

            }
        });

        //根据选择的类型展示相应的表格
        $("#coupon").change(function () {
            var coupon = $(this).children('option:selected').val();
            if (coupon == 1) {
                $('#coupon-content').css('display','block');
            } else if (coupon == 0) {
                $('#coupon-content').css('display','none');
            }
        });


    });
</script>

<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>